define([
  'text!../tmpl/app.html',
  './lists/add',
  './lists/edit',
  'backbone', 
  'underscore'
], function(tmpl, AddListView, EditListView, Backbone, _) {
  var AppView = Backbone.View.extend({
    el: '#main',
    template: _.template(tmpl),
    events: {
      "click #add-list-button": 'addList',
      "click #edit-list-button": 'editList',
      'click #delete-list-button': 'deleteList'
    },
    initialize: function() {

    },
    render: function() {
      this.$el.html(this.template());
      return this;
    },
    addList: function() {
      var lists = new baker211b.collections.lists.model({text: ''});
      var form = new AddListView({ model: lists });
      var self = this;

      this.$el.find('#list-editor').html(form.render().el).show();
      form.$el.find('input:first').focus();
      return false;
    },
    editList: function() {
      var form = new EditListView({model: baker211b.views.activeListMenuItem.model})
      this.$el.find('#list-editor').html(form.render().el).show();
      form.$el.find('input:first').focus();

      return false;
    },
    deleteList: function() {
      if (confirm('Are you sure you want to delete that list?')) {
        baker211b.views.activeListMenuItem.model.destroy();
      }
      return false;
    }
  })

  return AppView;
})
